package cn.edu.just.firstjavaapp.l21;

import javax.swing.*;
import java.awt.*;

public class DrawDemo extends JPanel {
    @Override
    public void paint(Graphics g) {
        super.paint(g);

        g.setColor(new Color(255,0,0));
        g.drawLine(0,0,200,200);
        g.setColor(new Color(0,0,255));
        g.drawString("我的图画",100,50);
        g.drawArc(100,100,80,100,0,180);
        g.drawRoundRect(200,200,100,80,25,25);
        g.setColor(Color.pink);
        g.fillOval(300,300,200,300);
        System.out.println("paint is called");
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawOval(10,10,20,20);
        System.out.println("painComponent");
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("我的画图");
        frame.setBounds(200,200,1000,800);
        DrawDemo drawDemo = new DrawDemo();
        drawDemo.setBackground(Color.white);
        frame.add(drawDemo);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
